package com.bearingnavi.android.util;

import com.bearingnavi.android.services.LocationService;
import com.bearingnavi.android.views.RotateView;

import android.content.Context;
import android.content.SharedPreferences;

public class Preferences {
	private SharedPreferences mPrefs;
	private static Preferences instance;
	
	private Preferences(Context context) {
		mPrefs = context.getSharedPreferences("BearingNaviPrefs", 0); //0 = mode private. only this app can read these preferences
	}
	
	public static Preferences createInstance(Context context) {
		instance = new Preferences(context);
		
		return instance;
	}
	
	public static Preferences getInstance() {
		return instance;
	}
	
	
	public void applyAllSettings() {

		LocationService.setFollowTheLocation(getFollowMe());
		
		if (getRotateMap()) {
			RotateView.getInstance().enableRotating();
		} else {
			RotateView.getInstance().disableRotating(true);
		}
	}
	
	public boolean getFirstRun() {
		return mPrefs.getBoolean("firstRun", true);
	}
	 
	public void setRunned() {
		SharedPreferences.Editor edit = mPrefs.edit();
		edit.putBoolean("firstRun", false);
		edit.commit();
	}
	
	public void setNotRunned() { // for debug only
		SharedPreferences.Editor edit = mPrefs.edit();
		edit.putBoolean("firstRun", true);
		edit.commit();
	}
	
	public void setSendLog(Boolean send) {
		SharedPreferences.Editor edit = mPrefs.edit(); 
		edit.putBoolean("sendLog", send);
		edit.commit();
	}
	
	public boolean getSendLog() {
		return mPrefs.getBoolean("sendLog", true);
	}
	
	public void setFollowMe(Boolean followMe) {
		SharedPreferences.Editor edit = mPrefs.edit(); 
		edit.putBoolean("followMe", followMe);
		edit.commit();
	}
	
	public boolean getFollowMe() {
		return mPrefs.getBoolean("followMe", true);
	}
	
	public void setRotateMap(Boolean rotateMap) {
		SharedPreferences.Editor edit = mPrefs.edit(); 
		edit.putBoolean("rotateMap", rotateMap);
		edit.commit();
	}
	
	public boolean getRotateMap() {
		return mPrefs.getBoolean("rotateMap", true);
	}
	
	 
}
